#!/bin/csh

#PBS -l nodes=125:ppn=32:xe
## set the number of nodes and number of processes per node (max 32)
#PBS -l walltime=02:30:00
## set the wallclock time
#PBS -N reciprocity
## set the job name
#PBS -q normal
#PBS -o ${PBS_JOBID}.out
#PBS -j oe
#PBS -m bea

echo `date`

# here's an example of how to set up a run directory on a scratch file system
#cd ~/IMC+emission/ # change to the directory containing all your IMC+emission subfolders
#mkdir -p /scratch/$PBS_JOBID # create a unique directory on scratch
# copy the current state of the model into your new scratch directory
# cp -r ./Domain-Files ./Drivers ./Integrators ./namelist ./out ./run ./src ./Tools  --target-directory=/scratch/$PBS_JOBID
# now change to that scratch directory
# cd /scratch/sciteam/aljones4/$PBS_JOBID


set batches = 200000
set photons = 50000
set albedo  = 0.0


foreach lambda (SW)
	if ($lambda == "SW")then
                set LW_flag = -1.0
        else
                set LW_flag = 1.0
        endif
    foreach atms(i3rc_Case4_lescu_2.13)
	set   domfile =(`echo ./Domain-Files/${atms}.dom`)
	foreach mu0(0.5 0.8660254)
	  if ($mu0 == "0.5")then
                set mu1 = 0.8660254
		set az0 = 60.0
		set az1 = 10.0
          else
                set mu1 = 0.5
		set az0 = 190.0
		set az1 = 240.0
          endif

	set outfile =(`echo ./out/${lambda}_${atms}_${mu0}_${mu1}_${batches}_${photons}.nc`)
						
		echo \&radiativeTransfer		>  ./namelist/basic.nml
		echo   solarFlux = 1.0,			>> ./namelist/basic.nml
		echo solarMu = $mu0		>> ./namelist/basic.nml
		echo solarAzimuth = $az0		>> ./namelist/basic.nml
		echo surfaceAlbedo = $albedo		>> ./namelist/basic.nml
		echo surfaceTemp = 290.6,		>> ./namelist/basic.nml
		echo intensityMus = $mu1,		>> ./namelist/basic.nml
		echo intensityPhis = $az1,		>> ./namelist/basic.nml
		echo angleFill = .false.		>> ./namelist/basic.nml
		echo   thetaFill =  -1.,		>> ./namelist/basic.nml
		echo   phiFill = -1.,			>> ./namelist/basic.nml
		echo LW_flag = $LW_flag			>> ./namelist/basic.nml
		echo lambda = 2.13,			>> ./namelist/basic.nml
		echo /					>> ./namelist/basic.nml
		echo \&monteCarlo			>> ./namelist/basic.nml
		echo numPhotonsPerBatch = $photons	>> ./namelist/basic.nml
		echo numBatches = $batches		>> ./namelist/basic.nml
		echo   iseed = 87,			>> ./namelist/basic.nml
		echo   nPhaseintervals = 1001		>> ./namelist/basic.nml
		echo /					>> ./namelist/basic.nml
		echo \&algorithms			>> ./namelist/basic.nml
		echo useRayTracing = .true.,		>> ./namelist/basic.nml
		echo useRussianRoulette = .false.,	>> ./namelist/basic.nml
		echo useRussianRouletteForIntensity = .false.,  >> ./namelist/basic.nml
		echo zetaMin = 0.3,			>> ./namelist/basic.nml
		echo useHybridPhaseFunsForIntenCalcs = .false.,  >> ./namelist/basic.nml
		echo hybridPhaseFunWidth = 0.,		>> ./namelist/basic.nml
		echo numOrdersOrigPhaseFunIntenCalcs = 0,  >> ./namelist/basic.nml
		echo limitIntensityContributions = .false.,  >> ./namelist/basic.nml
		echo maxIntensityContribution = 0.,	>> ./namelist/basic.nml
		echo /					>> ./namelist/basic.nml
		echo \&fileNames				>> ./namelist/basic.nml
		echo domainFileName = \"${domfile}\",	>> ./namelist/basic.nml
		echo outputNetcdfFile = \"${outfile}\"	>> ./namelist/basic.nml
		echo /					>> ./namelist/basic.nml
		echo \&output				>> ./namelist/basic.nml
		echo reportAbsorptionProfile = .true.,	>> ./namelist/basic.nml
		echo reportVolumeAbsorption = .true.	>> ./namelist/basic.nml
		echo recScatOrd = .false.		>> ./namelist/basic.nml
		echo numRecScatOrd = -1			>> ./namelist/basic.nml
		echo /					>> ./namelist/basic.nml

		echo started  run from $domfile at `date` ouput to $outfile
		aprun -n 4000 ./Drivers/monteCarloDriver ./namelist/basic.nml
		echo job finished at `date`
	end
    end
end
